
package com.fx.apartment.modules.house.controller;

import com.fx.apartment.common.support.Condition;
import com.fx.apartment.common.support.Query;
import com.fx.apartment.common.tool.api.R;
import com.fx.apartment.common.tool.lock.RedisLock;
import com.fx.apartment.common.tool.utils.Func;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import lombok.AllArgsConstructor;
import javax.validation.Valid;


import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestParam;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fx.apartment.modules.house.entity.Visitor;
import com.fx.apartment.modules.house.vo.VisitorVO;
import com.fx.apartment.modules.house.wrapper.VisitorWrapper;
import com.fx.apartment.modules.house.service.IVisitorService;


/**
 * 访客管理 控制器
 *
 * @author QinXueFeng
 * @since 2021-04-19
 */
@RestController
@AllArgsConstructor
@RequestMapping("/visitor")
@Api(value = "访客管理", tags = "访客管理接口")
public class VisitorController  {

	private final IVisitorService visitorService;

	/**
	 * 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入visitor")
	public R<VisitorVO> detail(Visitor visitor) {
		Visitor detail = visitorService.getOne(Condition.getQueryWrapper(visitor));
		return R.data(VisitorWrapper.build().entityVO(detail));
	}

	/**
	 * 分页 访客管理
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入visitor")
	public R<IPage<VisitorVO>> list(Visitor visitor, Query query) {
		IPage<Visitor> pages = visitorService.page(Condition.getPage(query), Condition.getQueryWrapper(visitor));
		return R.data(VisitorWrapper.build().pageVO(pages));
	}


	/**
	 * 新增或修改 访客管理
	 */
	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "新增或修改", notes = "传入visitor")
	@RedisLock("visitor::submit")
	public R submit(@Valid @RequestBody Visitor visitor) {
		return R.status(visitorService.saveOrUpdate(visitor));
	}


	/**
	 * 删除 访客管理
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 7)
	@ApiOperation(value = "逻辑删除", notes = "传入ids")
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(visitorService.deleteLogic(Func.toLongList(ids)));
	}

	
}
